package cn.itcast.bos.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.service.system.PermissionService;
import cn.itcast.fore.web.action.common.BaseAction;

@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PermissionAction extends BaseAction<Permission> {
	// 注入servcie
	@Autowired
	private PermissionService permissionService;

	// 显示菜单列表
	@Action("permission_list")
	public String list() {
		List<Permission> permissionList = permissionService.findByPermission();
		// 压入ROOT栈顶
		ActionContext.getContext().getValueStack().push(permissionList);
		return JSON;

	}

	@Action(value = "permission_add", results = { @Result(type = "redirect", location = "/pages/system/permission.html") })
	public String add() {
		permissionService.savePermission(model);
		return SUCCESS;

	}
}
